{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "from PIL import Image\n",
    "root = os.path.abspath('.')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "image_path = os.path.join(root,'JPEGImages')\n",
    "print(image_path)\n",
    "val_list_path = os.path.join(root,'ImageSets/Main/val.txt')\n",
    "\n",
    "image_list = os.listdir(image_path)\n",
    "f = open(val_list_path)\n",
    "val_images = os.path.join(root,'ImageSets/Main/val_images')\n",
    "for i in f.readlines():\n",
    "    i = i.strip()\n",
    "    print(i)\n",
    "    Image.open(os.path.join(image_path,i+'.jpg')).save(os.path.join(val_images,i+'.jpg'),'jpeg')\n",
    "f.close()    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1083"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val_list_path = os.path.join(root,'ImageSets/Main/val.txt')\n",
    "r = open('answer_xml.txt','w')\n",
    "f = open(val_list_path)\n",
    "tmp = []\n",
    "for i in f.readlines():\n",
    "    tmp.append(i+'.xml')\n",
    "r.write('\\n'.join(tmp))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
